package com.cius.util;

import com.cius.model.Sex;
import org.apache.struts2.util.StrutsTypeConverter;

import java.util.Map;

/**
 * 性别类型转换器
 * Created by CiusCheung on 16/9/18.
 */
public class SexConversion extends StrutsTypeConverter {
    @Override
    public Object convertFromString(Map arg0,String[] arg1,Class arg2){
        Sex[] sexs = Sex.values();
        for (Sex sex : sexs){
            if(sex.getName().equals(arg1[0])){
                return sex;
            }
        }
        return null;
    }
    
    @Override
    public String convertToString(Map arg0,Object arg1){
        Sex sex = (Sex) arg1;
        return sex.getName();
    }
}
